<?php
/**
 * Created by PhpStorm.
 * User: Shen
 * Date: 2016/6/29
 * Time: 22:13
 */
//面向过程实现mysqli连接

//1.连接
$link = mysqli_connect('localhost','root','123456','test') or die('连接错误'  . mysqli_connect_errno() . ':' . mysqli_connect_error());


//2.设置编码方式
mysqli_set_charset($link,'UTF8');


//3.执行SQL查询
$sql = "INSERT user(name, age, class) VALUES('张三', 12, '高三三班');";
$res = mysqli_query($link,$sql);

if ($res){
    echo mysqli_insert_id($link);
    echo  '<hr />';
    echo 'AFFECTED ROWS:' . mysqli_affected_rows($link);
}else{
    echo 'ERROR:SS<br />';
    echo mysqli_errno($link) . ':' . mysqli_error($link);
}


//关闭连接
mysqli_close($link);





